﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Controls_UC_Doithongtin : System.Web.UI.UserControl
{
    BUS_Customers customer = new BUS_Customers();
    BUS_Province province = new BUS_Province();
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
    }
    public void LoadData()
    {
        
        var dt = customer.Customers_GetByID(Session["UserName_Id"].ToString());
        txtFullName.Text = dt.Rows[0]["FullName"].ToString();
        txtBirthDay.Text =DayFomat(DateTime.Parse(dt.Rows[0]["Birthday"].ToString()));
        bool gt = bool.Parse(dt.Rows[0]["Sex"].ToString());
        if (gt)
        {
            rdbSexNam.Checked = true;
        }
        else
        {
            rdbSexNu.Checked = true;
        }
        txtAddress.Text = dt.Rows[0]["Address"].ToString();
        drlProvince.DataSource = province.Province_GetByAll();
        drlProvince.DataTextField = "Name";
        drlProvince.DataValueField = "Id";
        drlProvince.DataBind();
        drlProvince.SelectedValue = dt.Rows[0]["Province_Id"].ToString();
        txtMail.Text = dt.Rows[0]["Mail"].ToString();
        txtTel.Text = dt.Rows[0]["Tel"].ToString();

    }
    public string DayFomat(DateTime date)
    {
        return date.ToShortDateString();

    }

    protected void HoanTat_Click(object sender, EventArgs e)
    {
        bool gt;
        if(rdbSexNam.Checked) gt =true;
        else gt = false;
        string SET = string.Format("FullName = N'{0}', Birthday = '{1}', Sex = '{2}', Province_Id = '{3}', Address = '{4}', Tel = '{5}', Mail = '{6}'",txtFullName.Text, txtBirthDay.Text,gt,drlProvince.SelectedValue.ToString(),txtAddress.Text,txtTel.Text,txtMail.Text);
        customer.Customers_UpdateBySet(Session["UserName_Id"].ToString(), SET);
        Response.Redirect("Trangcanhan.aspx");
    }
}